/**
 * ExistRuleTableModel.java
 * @author: liuex
 * 2007-12-26 ����06:48:39
 *
 * note: 
 */
package org.lex.ftp.ui.prefs;

import javax.swing.table.AbstractTableModel;

import org.lex.ftp.util.prefs.FileAction;
import org.lex.ftp.util.prefs.FileActions;

public class FileRulesTableModel extends AbstractTableModel {
	private static final String[] COLUMN_NAMES = { "Destination", "Downloading", "Uploading", "FXP" };
	private static final String[] FIRST_COLUMN = { "Smaller", "Same", "Larger" };
	private FileAction[][] rules = null;
	private boolean contentChanged = false;

	public FileRulesTableModel() {
		this.rules = FileActions.getInstance().getActions();
	}

	public void restoreDefaults() {
		contentChanged = true;
		FileActions.loadDefaults(rules);
		this.fireTableDataChanged();
	}

	public boolean hasContentChanged() {
		return contentChanged;
	}

	public void saveToResourceMap() {
		FileActions.getInstance().setActions(rules);
	}

	@Override
	public boolean isCellEditable(int row, int column) {
		if (0 == column)
			return false;
		return true;
	}

	@Override
	public String getColumnName(int column) {
		return COLUMN_NAMES[column];
	}

	@Override
	public int getColumnCount() {
		return 4;
	}

	@Override
	public int getRowCount() {
		return 3;
	}

	@Override
	public Object getValueAt(int row, int column) {
		if (0 == column)
			return FIRST_COLUMN[row];
		return rules[row][column - 1].getDisplayName();
	}

	@Override
	public void setValueAt(Object value, int row, int column) {
		FileAction r = FileAction.byDisplayName(String.valueOf(value));
		rules[row][column - 1] = r;
		contentChanged = true;
	}
}
